using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;
using System.Linq;
using ZR.Model.Models.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;

namespace ZR.Service.Business
{
    /// <summary>
    ///  订单详情表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IOrderDetailInfoService), ServiceLifetime = LifeTime.Transient)]
    public class OrderDetailInfoService : BaseService<OrderDetailInfo>, IOrderDetailInfoService
    {
        /// <summary>
        /// 查询 订单详情表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<OrderDetailInfoDto> GetList(OrderDetailInfoQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<OrderDetailInfo, OrderDetailInfoDto>(parm);

            return response;
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public OrderDetailInfo GetInfo(int Id)
        {
            var response = Queryable()
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加 订单详情表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public OrderDetailInfo AddOrderDetailInfo(OrderDetailInfo model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改 订单详情表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateOrderDetailInfo(OrderDetailInfo model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<OrderDetailInfo> QueryExp(OrderDetailInfoQueryDto parm)
        {
            var predicate = Expressionable.Create<OrderDetailInfo>();

            return predicate;
        }
    }
}